<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            position: absolute;
            top: 0;
            left: 0;
            width: 100px;
            height: 100px;
            background-color: rgb(25, 225, 115);
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <script>
        let box = document.querySelector('.box');
        function move (box, target, dir, cb) {

            let timer = setInterval(() => {
                let realX = parseInt(getComputedStyle(box)[dir]) ;
                console.log(realX);
                let step = 10 * (target >realX ? 1 : -1 );
                
                if (realX === target) {
                    clearInterval(timer);
                    cb();
                } else {
                    let endX = realX + step + 'px';
                    box.style[dir] = endX;
                }
            },100)
        }
        move(box,300,'left',function() {
            move(box,300,'top',function(){
                move(box,0,'left',function(){
                    move(box,0,'top',function(){
                        
                    })
                })
            })
        })
    </script>
</body>
</html>